home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cfengine-1.5.3 / contrib / cron-shell-help-script / text0000.txt < prev   
Encoding:
Text File  |  1998-07-15  |  5.9 KB  |  172 lines

  1. Hi Mark,
  2. hi all!
  3.  
  4. I would like to contribute the following script "cfcron" to the cfengine 
  5. package. Basically it is a sh-script version of cfwrap. I wrote a 
  6. README (puh ;-) where everything else is explained.
  7.  
  8. If anybody has any problems running this script please send me a
  9. mail. I wrote it primarily for SunOS 4.1.x and Solaris, so if it doesn't
  10. work on other platforms you might have to do some minor changes or drop 
  11. me a mail, too.
  12.  
  13. Here we go, first the README, then the script. Hope you find it useful.
  14.  
  15. Cheers
  16.     Uwe
  17.  
  18. ------------------------cfcron.README-----------------------------------------
  19.     cfcron vers. 1.3 
  20.  
  21. cfcron is a wrapper script, which helps using CFengine from within
  22. cron. The output of a CFengine run will be mailed to the sysadmin only
  23. if it has changed, at least once a day. This script is more or less
  24. based on cfwrap which was written in perl by Mark Burgess. But I don't
  25. have perl around on all platforms, so I needed a shell script. Also
  26. this script has some features which are not found in cfwrap.
  27.  
  28. Before using cfcron you should adopt some variables at the
  29. beginning of the script (pathes etc.)
  30.  
  31. I think a short example will describe the usage best.
  32.  
  33. Suppose you have your cfengine scripts in a central repository
  34. which you mount to different hosts by NFS, let's say 
  35. /usr/local/etc/cfe. You might consider to put cfcron in
  36. /usr/local/etc. Now you can put an entry into all the crontab's 
  37. on all that hosts like this:
  38. 11 * * * * [ -x /usr/local/etc/cfe/cfcron ] && /usr/local/etc/cfe/cfcron
  39.  
  40. This entry will run CFengine ones per hour and mail you the
  41. results (if they have changed). Everything normal until here.
  42. But if you want to stop running CFengine on all hosts (e.g. for
  43. some testing) you normally have to rename the script or remove the 
  44. crontab entries. Another way is the one I use in this script: there
  45. is a global stop file, "noconf" e.g. in /usr/local/etc/cfe. This
  46. file prohibits the running of CFengine if it exists. So for the
  47. example above you just have to do a "touch /usr/local/etc/cfe/noconf"
  48. and you are done, cfcron will exit silently from now on.
  49.  
  50. Sometimes you might want to stop the execution of CFengine on just
  51. one host. For that reason (and for those guys starting every script
  52. lying around ;-) cfcron uses another file which permits the running 
  53. of CFengine. It looks for a file named ".ok" in the current directory,
  54. which is if cfcron is run by cron the homedir of the crontab owner
  55. (in most cases root). But if cfcron is started accidently, one will
  56. (hopefully) not be in the home directory. So this mechanism might be
  57. helpful to avoid running a complete CFengine job by mistake. If the
  58. ok file does not exist cfcron will send a mail that it is disabled.
  59.  
  60. In system administration CFengine does a great job, but it could be
  61. pretty dangerous too, cause it can do a lot of damage if not used
  62. careful, especially if you let it run by cron. With those
  63. possibilities described above it might be a bit more safely to let it
  64. run automatically on a bigger no. of hosts.
  65.  
  66. So many words for such a small script...
  67.  
  68. Uwe Sievers, <uwe@dwelle.de>, 1998
  69. ------------------------cfcron-----------------------------------------------
  70. #!/bin/sh
  71. ##############################################################
  72. #
  73. # wrapper script, mails output if there is any (and if changed)
  74. # Mainly intended for running cfengine; more or less based on
  75. # cfwrap which is written in perl. Also this one has some 
  76. # "enhancements" (see the README). 
  77. #
  78. # (us) 21-12-97 v1.1
  79. # (us) 23-12-97 v1.2 ok-file permits execution (local)
  80. #             noconf prohibits execution (global)
  81. #             on all hosts (silent)
  82. # (us) 24-12-97 v1.3 Fixed: mail problem if error in cfe-script (could 
  83. #                    not find sysadmin)
  84. #
  85. # Solaris Version & SunOS
  86. #
  87. # Copyright (c) Uwe Sievers 1997/98    <uwe@dwelle.de>
  88. # GPL rules, vers. 2 or newer. Use this program at your own risk!
  89. ##############################################################
  90. #
  91. #----------------------- adopt to your needs ----------------------
  92. FILECF="/usr/local/etc/cfe/cron/cron.cf"
  93. CFENGINE=/usr/local/sbin/cfengine
  94. TMPFILE=/var/tmp/cfwrap.$$
  95. OLDFILE=/var/tmp/cfwrap.o
  96. NOCONF=/usr/local/etc/noconf
  97. USER=`/usr/ucb/whoami`
  98. HOST=`/usr/bin/hostname`
  99. MAILER=/usr/bin/mailx
  100. #------------------no changes should be nessesary below (hopefully)
  101. COMM="$CFENGINE -f $FILECF"
  102. SYSV=
  103. BSD=
  104. OK=
  105.  
  106.  
  107. #cfe Vars
  108. OSREL=`uname -r`
  109. OSVERS=`uname -s`
  110. export OSREL OSVERS
  111.  
  112. if [ "$USER" != "root" ] ; then
  113.     echo "Bad luck, only root can run this one!"
  114.     $MAILER -s "$USER tried to run cfcron on $HOST" root </dev/null
  115.     exit 1
  116. fi
  117.  
  118. # just a hook
  119. if [ $OSVERS = SunOS -a $OSREL -lt 5 ] ; then
  120. #    echo BSD
  121.     :
  122. else
  123. #    echo SYSV
  124.     :
  125. fi
  126.  
  127. if [ -f $NOCONF ] ; then        # exit silently
  128.     exit 1
  129. fi
  130.  
  131. if [ -f .ok ] ; then 
  132.     OK=true
  133. else
  134.     COMM=/bin/true
  135.     unset OK
  136. #    exit 0
  137. fi
  138.  
  139. # does not work in case of error in cfe script
  140. #SYSADM=`$CFENGINE -a -S -w -f $FILECF 2>/dev/null` 
  141.  
  142. SYSADM=`egrep '^[^#].*sysadm.*=' $FILECF | cut -f2 -d\( | cut -f1 -d\)`
  143.  
  144. SUBJECT="cfengine on $HOST start at `date`" 
  145.  
  146. echo "This message originates from host $HOST on `date '+%d.%m.%y'`" \
  147.                         >> $TMPFILE
  148. if [ -n "$OK" ] ; then
  149.     echo "The full command issued was: $COMM"   >> $TMPFILE
  150. else
  151.     echo "d i s a b l e d"            >> $TMPFILE
  152. fi
  153.  
  154. [ -n "$OK" ] && $COMM >>$TMPFILE 2>&1
  155.  
  156. # only send mail if anything changes
  157. /usr/bin/diff $TMPFILE $OLDFILE >/dev/null ||
  158.     $MAILER -s "$SUBJECT" $SYSADM < $TMPFILE
  159.  
  160. rm $OLDFILE
  161. mv $TMPFILE $OLDFILE
  162. chmod 600 $OLDFILE
  163. exit 0
  164. --------------------------end----------------------------------------
  165. -- 
  166. ________      ____Deutsche Welle Berlin radio & tv broadcasting________
  167.    | \  \    /    Uwe Sievers        (system administrator)
  168.    | /   \/\/     <sievers@dwelle.de>    Tel.: +49 30 4646 8121 
  169. =========================USENET is *not* the non-clickable part of WWW!
  170.  
  171.  
  172.